<p class="Paragraph"><help:paragraphinfo state="U" number="51" xmlns:help="http://openoffice.org/2000/help"/>Many Uno interfaces let you register listeners on a special listener interface. This allows you to listen for specific events and call up the appropriate listener method. The CreateUnoListener function waits for the called listener interface and then passes the interface an object that the interface supports. This object is then passed to the method to register the listener.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="47" xmlns:help="http://openoffice.org/2000/help"/>The following example is based on a Basic library object.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="44" xmlns:help="http://openoffice.org/2000/help"/>The CreateUnoListener method requires two parameters. The first is a prefix and is explained in detail below. The second parameter is the fully qualified name of the Listener interface that you want to use.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="43" xmlns:help="http://openoffice.org/2000/help"/>The Listener must then be added to the Broadcaster Object. This is done by calling the appropriate method for adding a Listener. These methods always follow the pattern "addFooListener", where "Foo" is the Listener Interface Type, without the 'X'. In this example, the addContainerListener method is called to register the XContainerListener:</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="39" xmlns:help="http://openoffice.org/2000/help"/>The Listener is now registered. When an event occurs, the corresponding Listener calls the appropriate method from the com.sun.star.container.XContainerListener Interface.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="38" xmlns:help="http://openoffice.org/2000/help"/>The prefix calls registered Listeners from Basic-subroutines. The Basic run-time system searches for Basic-subroutines or functions that have the name "PrefixListenerMethode" and calls them when found. Otherwise, a run-time error occurs.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="37" xmlns:help="http://openoffice.org/2000/help"/>In this example, the Listener-Interface uses the following methods:</p>
<p class="P2"><help:paragraphinfo state="U" number="35" xmlns:help="http://openoffice.org/2000/help"/>Listener base interface (com.sun.star.lang.XEventListener): base interface for all Listener Interfaces</p>
<p class="P2"><help:paragraphinfo state="U" number="31" xmlns:help="http://openoffice.org/2000/help"/>Method of the com.sun.star.container.XContainerListener interface</p>
<p class="P2"><help:paragraphinfo state="U" number="29" xmlns:help="http://openoffice.org/2000/help"/>Method of the com.sun.star.container.XContainerListener interface</p>
</li>
</ul>
<p class="Paragraph"><help:paragraphinfo state="U" number="28" xmlns:help="http://openoffice.org/2000/help"/>In this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic:</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="23" xmlns:help="http://openoffice.org/2000/help"/>An event structure type that contains information about an event exists for every Listener type. When a Listener method is called, an instance of this event is passed to the method as a parameter. Basic Listener methods can also call these event objects, so long as the appropriate parameter is passed in the Sub declaration. For example:</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="6" xmlns:help="http://openoffice.org/2000/help"/>You do not need to include the parameter of an event object if the object is not used:</p>
<p class="PropText"><help:paragraphinfo state="U" number="5" xmlns:help="http://openoffice.org/2000/help"/>' Minimal implementation of Sub disposing</p>
<p class="Paragraph"><draw:image draw:name="Icon0" svg:desc="This icon marks text containing important information on data and system security." svg:pixelx="32" svg:pixely="32" svg:width="0.847cm" svg:height="0.847cm" xlink:href="65640" draw:filter-name="" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/></p>